﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessCardReportLoss
// 文件功能描述：卡片挂失数据访问层
//
// 
// 创建标识：2012-02-20 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessCardReportLoss
    {
        /// <summary>
        /// 获取已发卡未挂失的信息
        /// </summary>
        /// <returns></returns>
        public DataSet SelCardReportLossInfo(int pagesize, int startindex, string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY PID ASC) rownumber,* " +
                               "from Lost_Card_View where 1=1 " + strquery + ") B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 已发卡未挂失的数量
        /// </summary>
        /// <returns></returns>
        public int GetCardReportLossCount()
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Lost_Card_View";
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 根据条件已发卡未挂失的数量
        /// </summary>
        /// <returns></returns>
        public int GetCardReportLossCountWhere(string query1)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Lost_Card_View where 1=1 " + query1;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                string query = "select Dep_ID,deptName from DeptView order by Dep_ID";
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 挂失卡片
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int ReportLoss(string PID, string OperatorID)
        {
            sqldb db = new sqldb();
            string query = "UPDATE CARD_CARD SET STATUS=2 WHERE STATUS=0 AND PID='" + PID +
                "' insert into Card_Cardchange (PID,ChangeReason,CardSerial,OperatorID) values(" + PID + ",2,0,'" + OperatorID + "')";
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }
    }
}
